//
//  MyOfferInformationViewModel.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/3.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "MyOfferInformationViewModel.h"
#import "MyGoodsOfferInforTableViewCell.h"
#import "NoDataFootTableViewHeaderFooterView.h"
#import "MyOfferHeInforTableViewCell.h"
#import "RequirementsTableViewCell.h"
#import "MyOfferDepositTableViewHeaderFooterView.h"
#import "MyOfferBottomView.h"
#import "MyOfferBottomView.h"

@interface MyOfferInformationViewModel ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation MyOfferInformationViewModel

-(instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        tableView.height = tableView.height - kHeightProportion_In_iPhoneTriploid(60);
        tableView.mj_footer.hidden = YES;
        tableView.mj_header.hidden = YES;
        tableView.dataSource= self;
        tableView.delegate = self;
        [tableView registerClass:[NoDataFootTableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"NoDataFootTableViewHeaderFooterView"];
        [tableView registerClass:[MyOfferDepositTableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"MyOfferDepositTableViewHeaderFooterView"];
        [superView addSubview:tableView];
        //
        MyOfferBottomView * offButtomView = [[MyOfferBottomView alloc] initWithFrame:CGRectMake(0, kY_With_View(tableView, 0), KScreenWidth, kHeightProportion_In_iPhoneTriploid(60)) inSuperView:superView];
        
    }
    return self;
}

#pragma mark -- UITableViewDataSource,UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat cellHeaght = 0;
    switch (indexPath.section) {
        case 0:{
            cellHeaght = kHeightProportion_In_iPhoneTriploid(235);
        }
            break;
        case 1:{
            if (indexPath.row == 0) {
                cellHeaght = kHeightProportion_In_iPhoneTriploid(117);
            }else{
                cellHeaght = kHeightProportion_In_iPhoneTriploid(120);
            }
        }
            break;
            
        default:
            break;
    }
    return cellHeaght;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BaseTableViewCell * cell;
    switch (indexPath.section) {
        case 0:{
            MyGoodsOfferInforTableViewCell * cell_offer = [MyGoodsOfferInforTableViewCell cellWithTableView:tableView];
            cell_offer.Block_LookInfor = ^{
                if (self.delegate && [self.delegate respondsToSelector:@selector(offerPushGoodsInformation)]) {
                    [self.delegate offerPushGoodsInformation];
                }
            };
            cell = cell_offer;
        }
            break;
        case 1:{
            if (indexPath.row == 0) {
                RequirementsTableViewCell * cell_rements = [RequirementsTableViewCell cellWithTableView:tableView];
                cell = cell_rements;
            }else{
                MyOfferHeInforTableViewCell * cell_infor = [MyOfferHeInforTableViewCell cellWithTableView:tableView];
                cell = cell_infor;
            }
        }
            break;
            
        default:
            break;
    }
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UITableViewHeaderFooterView * headerView;
    if (section == 0) {
        MyOfferDepositTableViewHeaderFooterView * headerView_deposit = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"MyOfferDepositTableViewHeaderFooterView"];
        headerView = headerView_deposit;
    }else{
        NoDataFootTableViewHeaderFooterView * footView_no = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
        headerView = footView_no;
    }
    
    return headerView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return kHeightProportion_In_iPhoneTriploid(73);
    }else{
        return 0.01;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    NoDataFootTableViewHeaderFooterView * footView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
    return footView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return 0.01;
    }else{
        return kHeightProportion_In_iPhoneTriploid(10);
    }
}

@end
